#pragma once

#include "FrogBaseDialog.h"
#include "FilerFrogUpdater.h"

#define WM_NO_NEW_UPDATE WM_APP+1
#define WM_FOUND_NEW_UPDATE WM_APP+2
#define WM_FINISH_UPDATE WM_APP+3

class CUpdateWindow : public CFrogBaseDialog<CUpdateWindow>
{
public:

	CUpdateWindow(bool silent=false);
	~CUpdateWindow();

	enum { IDD = IDD_DIALOG_UPDATE };

	BEGIN_MSG_MAP(CUpdateWindow)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
		// Custom Message
		MESSAGE_HANDLER(WM_NO_NEW_UPDATE, OnNoNewUpdate)
		MESSAGE_HANDLER(WM_FOUND_NEW_UPDATE, OnFoundUpdate)
		MESSAGE_HANDLER(WM_FINISH_UPDATE, OnFinishUpdate)
		// FrogBaseDialog Inherited
		CHAIN_MSG_MAP(CFrogBaseDialog)
	END_MSG_MAP()

	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);	

private:
	bool m_Silent;
	FilerFrogUpdater m_FilerFrogUpdater;
	HANDLE m_hThreadProgress;
	bool m_DownloadUpdate;

	static DWORD WINAPI RunCUpdateThread(LPVOID lpParam);

	LRESULT OnNoNewUpdate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnFoundUpdate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnFinishUpdate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
};